﻿using System;
using System.Data.Entity;
using System.Diagnostics;
using System.Security.Principal;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using AModelTest;
using GiveGraphMappers;
using GiveGraphModel;
using Microsoft.IdentityModel.Claims;
using Microsoft.IdentityModel.Web;
using Microsoft.Web.Mvc;
using WebApp.Models;
using WebApp.Util;

namespace WebApp
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "About",
                "About",
                new { controller = "Home", action = "About" }
            );

            routes.MapRoute(
                "Profile",
                "Profile",
                new { controller = "Account", action = "Index"}
            );

            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );
        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            ValueProviderFactories.Factories.Add(new JsonValueProviderFactory());

            //FederatedAuthentication.ServiceConfigurationCreated += (o, e) =>
            //                                                           {
            //                                                               FederatedAuthentication.WSFederationAuthenticationModule.SignedIn += (oo, ee) =>
            //                                                               {
            //                                                                   HttpContext.Current.User = new CustomUser(User);
            //                                                               };
            //                                                           }; 
            

            RegisterRoutes(RouteTable.Routes);
            //ModelBinders.Binders.Add(typeof (Schedule), new ScheduleBinder());
            //Database.SetInitializer<GiveGraphContext>(new SeedOnModelChangeModelChange());
        }

        //protected void Application_Error(object sender, EventArgs e)
        //{
        //    HttpException exception = Server.GetLastError() as HttpException;

        //    switch (exception.GetHttpCode())
        //    {
        //        case 404: Response.Redirect("/Error/Error404");
        //            break;
        //        default : Response.Redirect("Error");
        //            break;
        //    }
        //}
    }
}